import {NavBar} from "antd-mobile";
import PropTypes from "prop-types";
import './NavbarAgain'
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'

const NavbarAgain = (props) => {
    const { title } = props
    const navigate = useNavigate()
    const location = useLocation()
    const [usp] = useSearchParams()
    const handleBack = () => {
        // 特殊页：登录页
        let to = usp.get('to')
        // console.log(usp);      
        if (location.pathname === '/login' && /^\/detail\/\d+$/.test(to)) {
            navigate(to, { replace: true })
            return
        }  
        navigate(-1)

    }
    return <>
        <NavBar  onBack={handleBack}
                className="bavbar-again-box">
            {title}
        </NavBar>
    </>

};

// 设置传参
NavbarAgain.defaultProps = {
    title:'个人中心'
}
NavbarAgain.propTypes = {
    title:PropTypes.string
}
export default NavbarAgain
